#include <bits/stdc++.h>
using namespace std;

using ll = long long;
ll count()
{
}
mt19937 rd;
int main()
{
	freopen("run.in", "r", stdin);
	freopen("run.out", "w", stdout);
	//freopen!!!
	//freopen!!!
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int C, T, n, m, k, d, i, x, y, v;
	ll ans = 0;
	cin >> C >> T;
	while (T--)
	{
		cin >> n >> m >> k >> d;
		for (i = 1; i <= m; ++i)
		{
			cin >> x >> y >> v;
			ans += (rd() > rd() ? v : 0);
		}
		cout << ans << '\n';
	}
	return 0;
}

